<?php
declare (strict_types = 1);
namespace app\index\model\car;

use think\Model;

/**
 * @mixin \think\Model
 */
class CarBrand extends Model
{
    protected $pk = "id";

    /**
     * 获取信息
     * @param $where
     * @return array|null|Model
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    function getInfoByWhere($where){
        return $this->where($where)->find();
    }

    /**
     * 获取列表
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    function getList($getData){
        if(isset($getData['brand_name']) && $getData['brand_name']){
            $sql = $this->whereLike('brand_name','%'.$getData['brand_name']."%");
        }else{
            $sql = $this;
        }
        $getList = $sql->order('brand_letter','asc')->select();
        if($getList){
            $getList = $getList->toArray();
            $setData = [];
            foreach ($getList as $key=>$value){
                if(!$value['brand_logo']) $value['brand_logo'] = config('add.web_url')."/static/imgs/kuodaLogo.png";
                $setData[$value['brand_letter']][] = $value;
            }
            return $setData;
        }else{
            return [];
        }
    }

}
